package com.shukesmart.speech.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;

import com.shukesmart.speech.R;

import java.io.IOException;

import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

public class SpeechDialog {
    static GifImageView gifImageView;
    static GifDrawable gifDrawable;
    static AlertDialog dialog;
    public static void show(Activity activity) throws IOException {

// 在Activity中
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        LayoutInflater inflater = activity.getLayoutInflater();

// 通过LayoutInflater获取对话框布局
        View dialogView = inflater.inflate(R.layout.dialog_image, null);
        gifDrawable = new GifDrawable(activity.getResources(), R.drawable.yuyin);

        gifImageView = dialogView.findViewById(R.id.gifImageView);
        gifImageView.setImageDrawable(gifDrawable);
        gifDrawable.start();
        builder.setView(dialogView);

        builder.setCancelable(false);
// 创建并显示对话框
        dialog = builder.create();
        dialog.getWindow().setDimAmount(0f);

        dialog.show();
    }

    public static void hide() {
        if (gifDrawable != null) {
            gifDrawable.stop();
        }
        if(dialog!=null){
            dialog.dismiss();
        }
    }
}
